﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BLL;

public partial class Login_Login : System.Web.UI.Page
{
    BLL.UserBean userBean = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        userBean = new UserBean();
        string error = Request.QueryString["error"];
        if(!string.IsNullOrEmpty(error)){
            int code = Convert.ToInt32(error);
            string showMsg = "";
            switch (code){
                case 1:
                    showMsg = "登录失败:验证码错误";
                    break;
                case 2:
                    showMsg = "账户名和密码不匹配，或该用户不存在";
                    break;
                default:
                    showMsg = "";
                    break;
            }
            this.Lbl_ErrorInfo.Text = showMsg;
        }

    }

    //-----------------------------------------------
    protected void ImgBtn_Login_Click(object sender, ImageClickEventArgs e)
    {
        //比对验证码
        string validateCode = this.Txt_validateCode.Text.Trim();
        string mobile = WebUtility.replaceStr(this.Txt_UserMobile.Text.Trim());
        string pwd = WebUtility.replaceStr(this.Txt_Pwd.Text.Trim());
        string userType = this.RBL_UserType.SelectedValue;// 1:个人；2：企业
        bool isValidated = false;

        string systemValidateCode = "";
        if (Session["webValidateCode"] != null)
        {
            systemValidateCode = Session["webValidateCode"].ToString();

        }
        //验证码相同
        if (string.Compare(validateCode, systemValidateCode, true) == 0)
        {
             isValidated = userBean.ValidateLoginUser(mobile, pwd, userType);
             if (isValidated == true)
             {
                 Session["LoginUser"] = mobile;
                 Response.Redirect(WebUtility.getWebRootPath() + "/MyLy/Mylyindex.aspx");
             }
             else 
             {
                 this.Lbl_ErrorInfo.Text = "账户名和密码不匹配，或该用户不存在";
             }
        }
        else
        {
            //error=1 验证码错误
           // Response.Redirect(WebUtility.getWebRootPath() + "/Login/Login.aspx?error=1");
            this.Lbl_ErrorInfo.Text = "登录失败:验证码错误";
        }
    }
}
